#include "agent_version.h"
#include "debug.h"
#include "app_util.h"
#include "utils.h"

namespace {

	// The version string is not visible outside this module and it is only
	// accessible through the PCAgent::GetVersionString accessor.
	CString version_string;

	ULONGLONG agent_version = 0;

}  // namespace

namespace pcagent
{

	// In both GetVersion* methods, we assert only that InitializeVersion* was
	// already called and not that they weren't called twice, which is OK.
	// There is no detection that the version_ variables aren't accessed before
	// being initialized because this would require accessor methods to enforce and
	// lead to bloat.

	const TCHAR* GetVersionString() {
		ASSERT1(!version_string.IsEmpty());
		return version_string;
	}

	ULONGLONG GetVersion() {
		ASSERT1(!version_string.IsEmpty());
		return agent_version;
	}

	void InitializeVersionFromModule(HINSTANCE instance) {
		ULONGLONG module_version = app_util::GetVersionFromModule(instance);

		InitializeVersion(module_version);
	}

	void InitializeVersion(ULONGLONG version) {
		agent_version = version;

		version_string = StringFromVersion(agent_version);
	}

}